<template>
  <rt-view>
    <rt-form ref="insertForm" :model="insertForm">
      <rt-header>
        <rt-list-header>
          <rt-header-icon slot="icon" icon="rt-base-account" />
          <rt-header-title title="审核评论" />
          <template slot="btn">
            <rt-header-button-group>
              <rt-button
                :plain="false"
                type="primary"
                icon-name="rt-portal-delete"
                @click="deleteComment"
              >
                删除
              </rt-button>
            </rt-header-button-group>
            <rt-button
              type="back"
              icon-name="rt-base-back"
              style="margin-left: 10px"
              @click="back"
              >返回</rt-button
            >
          </template>
        </rt-list-header>
      </rt-header>
      <rt-content>
        <rt-card>
          <rt-section icon="rt-base-account" title="基础信息">
            <rt-form-wrapper>
              <rt-row :gutter="32">
                <rt-col :span="24">
                  <rt-form-item label="评论内容">
                    <rt-input v-model="insertForm.text" readonly="readonly" />
                  </rt-form-item>
                </rt-col>
              </rt-row>
              <rt-row :gutter="32">
                <rt-col :span="12">
                  <rt-form-item label="文章标题">
                    <rt-input
                      v-model="insertForm.object_name"
                      readonly="readonly"
                    />
                  </rt-form-item>
                </rt-col>
                <rt-col :span="6">
                  <rt-form-item label="评论时间">
                    <rt-input
                      v-model="insertForm.createdon"
                      readonly="readonly"
                    />
                  </rt-form-item>
                </rt-col>
                <rt-col :span="6">
                  <rt-form-item label="客户名称">
                    <rt-input
                      v-model="insertForm.bbs_account_name"
                      readonly="readonly"
                    />
                  </rt-form-item>
                </rt-col>
              </rt-row>
              <rt-row :gutter="32">
                <rt-col :span="6">
                  <rt-form-item label="姓名">
                    <rt-input v-model="insertForm.name" readonly="readonly" />
                  </rt-form-item>
                </rt-col>
                <rt-col :span="6">
                  <rt-form-item label="昵称">
                    <rt-input
                      v-model="insertForm.nickname"
                      readonly="readonly"
                    />
                  </rt-form-item>
                </rt-col>
                <rt-col :span="6">
                  <rt-form-item label="电话">
                    <rt-input
                      v-model="insertForm.mobilephone"
                      readonly="readonly"
                    />
                  </rt-form-item>
                </rt-col>
              </rt-row>
            </rt-form-wrapper>
          </rt-section>
        </rt-card>
      </rt-content>
    </rt-form>
  </rt-view>
</template>

<script>
import RtCard from 'vue-xpc/src/components/card/rtCard';
import RtSection from 'vue-xpc/src/components/section/rtSection';
import util from '@/libs/util';
export default {
  name: 'CommentDetail',
  components: { RtSection, RtCard },
  data() {
    return {
      id: '',
      insertForm: {
        object_name: '',
        text: '',
        name: '',
        createdon: '',
        bbs_account_name: '',
        comment_by_name: '',
        nickname: '',
        mobilephone: ''
      }
    };
  },
  mounted() {
    this.id = this.$route.params.id;
    if (this.id != null && this.id !== '') {
      this.getCommentById(this.id);
    }
  },
  methods: {
    getCommentById(id) {
      rt.get('/api/bbs/postcommentlog/commentbyid/' + id).then(res => {
        this.insertForm = res;
        this.insertForm.createdon = this.$moment(res.createdon).format(
          'YYYY-MM-DD HH:mm'
        );
        //this.insertForm.createdon = util.formatDate(res.createdon);
      });
    },
    deleteComment() {
      this.$confirm('确定要删除该评论吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          const idList = [];
          idList.push(this.id);
          rt.post('/api/bbs/postcommentlog/muldelcomment', idList)
            .then(res => {
              if (res.ErrorCode === 0) {
                rt.showSuccessToast('成功');
                this.$router.replace({ path: '/comment/list' });
              }
            })
            .catch(error => {
              rt.showErrorToast(error);
            });
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
    },
    back() {
      this.$router.push({ path: '/comment/list' });
    }
  }
};
</script>

<style scoped></style>
